package com.zzb.servlet;


import com.zzb.model.CommentModel;
import com.zzb.service.CommentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;


@WebServlet("/comment")
public class CommentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.处理乱码
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());


        //2.得到前端数据

        //3.将数据封装到model


        //4.处理服务逻辑关系
        CommentService commentService = new CommentService();


        //5.得到处理返回值
        CommentModel commentModel = commentService.getCommentModel();

        req.setAttribute("commentModel",commentModel);


        //6.将数据返回到前端
        req.getRequestDispatcher("/jsp/comment.jsp").forward(req, resp);
    }
}
